package com.qdlc.p2p.dal.dto;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.qdlc.p2p.common.constant.Global;
import com.qdlc.p2p.common.util.DateUtil;
import com.qdlc.p2p.dal.common.LogTemplateHelper;

/**
 * 资金操作日志表
 *
 * @author liya
 * @version 1.1.0.0
 */
@Entity
@Table(name = Global.DB_PREFIX + "account_log")
public class AccountLog {

    /** 主键 */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    /** 用户ID */
    @Column(name = "user_id")
    private long userId;

    /** 类型 产生这条记录的操作 */
    private String type;

    /** 账户总额 */
    private double total;

    /** 操作金额 */
    private double money;

    /** 可用金额 */
    private double useMoney;

    /** 冻结金额 */
    private double noUseMoney;

    /** 待收金额 */
    private double collection;

    /** 交易对方的user_id */
    @Column(name = "to_user")
    private long toUserId;

    /** 资金记录类型名称 */
    private String name;

    /** 备注 */
    private String remark;

    /** 添加时间 */
    private Date addTime;

    /** 添加IP */
    private String addIp;

    /** 收支明细 0：不变  1：收入  2：支出, 3: 充值 ,4: 提现，5：新浪存钱罐收益，6：托管对账 */
    private byte paymentsType;

    public AccountLog() {
        this.addTime = DateUtil.getNow();
        this.addIp = Global.getIP();
    }

    public AccountLog(User user, String type, User toUser) {
    	this.userId = (user == null ? 0 : user.getUserId());
        this.type = type;
        this.toUserId = (toUser == null ? -1 : toUser.getUserId());
        this.addTime = DateUtil.getNow();
        this.addIp = Global.getIP();
        this.name = LogTemplateHelper.getLogTempName(2, type);
        this.paymentsType = LogTemplateHelper.getPaymentType(2, type);
    }

    public AccountLog(User user, String type, double total, double money, double useMoney, double noUseMoney,
                      double collection, User toUser, String remark) {
        super();
        this.userId = (user == null ? 0 : user.getUserId());
        this.type = type;
        this.total = total;
        this.money = money;
        this.useMoney = useMoney;
        this.noUseMoney = noUseMoney;
        this.collection = collection;
        this.toUserId = (toUser == null ? -1 : toUser.getUserId());
        this.remark = remark;
        this.addTime = DateUtil.getNow();
        this.addIp = Global.getIP();
        this.name = LogTemplateHelper.getLogTempName(2, type);
        this.paymentsType = LogTemplateHelper.getPaymentType(2, type);
    }

    /**
     * 获取主键
     *
     * @return 主键
     */
    public long getId() {
        return id;
    }

    /**
     * 设置主键
     *
     * @param id 要设置的主键
     */
    public void setId(long id) {
        this.id = id;
    }


    public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}

	/**
     * 获取类型 产生这条记录的操作
     *
     * @return 类型 产生这条记录的操作
     */
    public String getType() {
        return type;
    }

    /**
     * 设置类型 产生这条记录的操作
     *
     * @param type 要设置的类型 产生这条记录的操作
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * 获取账户总额
     *
     * @return 账户总额
     */
    public double getTotal() {
        return total;
    }

    /**
     * 获取账户总额显示值
     *
     * @return 账户总额显示值
     */
    public String getTotalDisp() {
        return String.valueOf(total).concat("元");
    }

    /**
     * 设置账户总额
     *
     * @param total 要设置的账户总额
     */
    public void setTotal(double total) {
        this.total = total;
    }

    /**
     * 获取操作金额
     *
     * @return 操作金额
     */
    public double getMoney() {
        return money;
    }

    /**
     * 获取操作金额显示值
     *
     * @return 操作金额显示值
     */
    public String getMoneyDisp() {
        return String.valueOf(money).concat("元");
    }

    /**
     * 设置操作金额
     *
     * @param money 要设置的操作金额
     */
    public void setMoney(double money) {
        this.money = money;
    }

    /**
     * 获取可用金额
     *
     * @return 可用金额
     */
    public double getUseMoney() {
        return useMoney;
    }

    /**
     * 获取可用金额显示值
     *
     * @return 可用金额显示值
     */
    public String getUseMoneyDisp() {
        return String.valueOf(useMoney).concat("元");
    }

    /**
     * 设置可用金额
     *
     * @param useMoney 要设置的可用金额
     */
    public void setUseMoney(double useMoney) {
        this.useMoney = useMoney;
    }

    /**
     * 获取冻结金额
     *
     * @return 冻结金额
     */
    public double getNoUseMoney() {
        return noUseMoney;
    }

    /**
     * 获取冻结总额显示值
     *
     * @return 冻结总额显示值
     */
    public String getNoUseMoneyDisp() {
        return String.valueOf(noUseMoney).concat("元");
    }

    /**
     * 设置冻结金额
     *
     * @param noUseMoney 要设置的冻结金额
     */
    public void setNoUseMoney(double noUseMoney) {
        this.noUseMoney = noUseMoney;
    }

    /**
     * 获取待收金额
     *
     * @return 待收金额
     */
    public double getCollection() {
        return collection;
    }

    /**
     * 获取待收总额显示值
     *
     * @return 待收总额显示值
     */
    public String getCollectionDisp() {
        return String.valueOf(collection).concat("元");
    }

    /**
     * 设置待收金额
     *
     * @param collection 要设置的待收金额
     */
    public void setCollection(double collection) {
        this.collection = collection;
    }


    public long getToUserId() {
		return toUserId;
	}

	public void setToUserId(long toUserId) {
		this.toUserId = toUserId;
	}

	/**
     * 获取资金记录类型名称
     *
     * @return 资金记录类型名称
     */
    public String getName() {
        return name;
    }

    /**
     * 设置资金记录类型名称
     *
     * @param name 资金记录类型名称
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取备注
     *
     * @return 备注
     */
    public String getRemark() {
        return remark;
    }

    /**
     * 设置备注
     *
     * @param remark 要设置的备注
     */
    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    /**
     * 获取添加IP
     *
     * @return 添加IP
     */
    public String getAddIp() {
        return addIp;
    }

    /**
     * 设置添加IP
     *
     * @param addIp 要设置的添加IP
     */
    public void setAddIp(String addIp) {
        this.addIp = addIp;
    }

    public byte getPaymentsType() {
        return paymentsType;
    }

    public void setPaymentsType(byte paymentsType) {
        this.paymentsType = paymentsType;
    }
}
